#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int c[1000010], n;
bool a[1000010];

int lowbit(int x) {
	return x&-x;
}
void change(int x, int k) {
	while(x <= (n<<1)) {
		c[x] += k;
		x += lowbit(x);
	}
}
int sum(int x) {
	int ans = 0;
	while(x > 0) {
		ans += c[x];
		x -= lowbit(x);
	}
	return ans;
}

int main() {
	int t, x, y, order;
	scanf("%d", &t);
	while(t--) {
		memset(a, false, sizeof(a));
		memset(c, 0, sizeof(c));
		int m;
		scanf("%d%d", &n, &m);
		for(int i=1; i<=n+n+1; i++) {
			change(i, 1);
			a[i] = true;
		}
		while(m--) {
			scanf("%d%d", &order, &x);
			if(order == 1) {
				scanf("%d", &y);
				if(x > y)	swap(x, y);
				int s1 = sum(y-1) - sum(x-1);
				int s2 = sum(x+n-1) - sum(y-1);
				if(s1==y-x || s2==x+n-y)	printf("1\n");
				else						printf("0\n");
			} else {
				if(a[x])	change(x, -1), change(x+n, -1);
				else		change(x, 1), change(x+n, 1);
				a[x] = !a[x];
				a[x+n] = !a[x+n];
			}
		}
	}
	return 0;
}